package com.wzxy.nc.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wzxy.nc.dao.IBaseDao;
import com.wzxy.nc.dao.ISysUserDao;
import com.wzxy.nc.entity.SysUser;
import com.wzxy.nc.service.ISysUserService;

@Service
public class SysUserService extends BaseService<SysUser> implements ISysUserService{
	
	private static final Logger logger = LoggerFactory.getLogger(SysUserService.class);

	@Autowired
	private ISysUserDao userDao;
	
//	@Autowired
//	private WebSocket webSocket;
	
	@Override
	public void setBaseDao(IBaseDao<SysUser> baseDao){
		super.setBaseDao(userDao);
	}

	@Override
	protected void beforeInsert(SysUser t) {
		super.beforeInsert(t);
		System.out.println("执行插入的方法之前..." + t.getUsername());
	}

	@Override
	protected void afterInsert(SysUser t) {
		super.afterInsert(t);
		System.out.println("执行插入的方法之后..." + t.getPassword());
	}

	@Override
	public void testWebSocket() {
		Map<String,Object> map = new HashMap<>();
		map.put("code", 0);
		List<SysUser> userList = new ArrayList<>();
		SysUser user1 = new SysUser();
		user1.setId(1);
		user1.setUsername("123");
		user1.setPassword("123");
		userList.add(user1);
		
		SysUser user2 = new SysUser();
		user2.setId(1);
		user2.setUsername("222");
		user2.setPassword("123");
		userList.add(user2);
		
		//webSocket.sendMessage(0,map,userList);		
	}

	@Override
	public List<SysUser> findByUser(SysUser user) {
		return userDao.findByUser(user);
	}

	@Override
	public void delete(Integer id) {
		SysUser user = userDao.findById(id);
		user.setDeleteFlag(1);
		userDao.update(user);
	}

}
